package com.ald.plane_tool.ui.fragment;

import android.util.Log;

import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.recyclerview.widget.GridLayoutManager;

import com.ald.plane_tool.BR;
import com.ald.plane_tool.R;
import com.ald.plane_tool.adapter.HomeAdapter;
import com.ald.plane_tool.databinding.FragmentHomeBinding;
import com.ald.plane_tool.viewmodle.HomeViewModle;
import com.aleyn.mvvm.base.BaseFragment;

import java.util.ArrayList;
import java.util.List;

public class HomeFragment extends BaseFragment<HomeViewModle, FragmentHomeBinding> {
    private HomeAdapter myAdapter;
    private List<Integer> openApplist=new ArrayList<>();
    @Override
    public int initVariableID() {
        return BR.HomeViewModle;
    }

    @Override
    public void lazyLoadData() {

        Log.i("TAG", "lazyLoadData: "+888);
        if (openApplist==null||openApplist.size()<=0){
            openApplist.add(R.mipmap.hmapa);
            openApplist.add(R.mipmap.hmapb);
            openApplist.add(R.mipmap.hmapc);
            openApplist.add(R.mipmap.hmapd);
            openApplist.add(R.mipmap.hmapf);
            openApplist.add(R.mipmap.hmape);
        }
        myAdapter = new HomeAdapter(openApplist);
        GridLayoutManager layoutManager = new GridLayoutManager(getActivity(),3);
        layoutManager.setOrientation(GridLayoutManager.VERTICAL);
        mBinding.mdRecyclerviewContent.setLayoutManager(layoutManager);
        mBinding.mdRecyclerviewContent.setAdapter(myAdapter);
        NavController navController = Navigation.findNavController(getActivity(), R.id.fragment);
        myAdapter.addChildClickViewIds(R.id.cancel_action);
        myAdapter.setOnItemChildClickListener((adapter, view, position) -> {
            Log.i("frf", "home点击: "+position);
          switch (position){
              case 0:

// 跳转到secondFragment
                  navController.navigate(R.id.action_homeFragment_to_rockerFragment);
// 返回上一个Fragment
//                  navHostController.navigateUp()
                  break;
              case 1:
                  navController.navigate(R.id.action_homeFragment_to_calibrationFragment);
                  break;
              case 2:
                  navController.navigate(R.id.action_homeFragment_to_measurementFragment);
                  break;
              case 3:
                  navController.navigate(R.id.action_homeFragment_to_videoFragment);
                  break;
              case 4:
                  navController.navigate(R.id.action_homeFragment_to_frequencyFragment);
                  break;
              case 5:
                  navController.navigate(R.id.action_homeFragment_to_upgradeFragment);
                  break;

          }
        });
    }

    @Override
    public int layoutId() {
        return R.layout.fragment_home;
    }
}
